//
//  LBBaseViewController.swift
//  JLBWeibo
//
//  Created by 蒋良彪 on 16/7/2.
//  Copyright © 2016年 Color. All rights reserved.
//

import UIKit
import SnapKit

class LBBaseViewController: UITableViewController {
    
    var isLogin: Bool = false

    override func viewDidLoad() {
        super.viewDidLoad()

        lblText.text = "这里是：\(self.title!)"
    }
    
    override func loadView() {
        if isLogin {
            super.loadView()
        } else {
            setupUnLoginView()
            setupNav()
            setupUI()
            setupLayout()
        }
    }

    @objc private func setupUnLoginView() {
        view = LBUnLoginView()
    }
    
    @objc private func setupUI() {
        self.view.addSubview(lblText)
        self.view.addSubview(loginButton)
        self.view.addSubview(registerButton)
    }
    
    @objc private func setupLayout() {
        lblText.snp_makeConstraints { (make) in
            make.center.equalTo(self.view)
        }
        
        loginButton.snp_makeConstraints { (make) in
            make.top.equalTo(lblText).offset(20)
            make.left.equalTo(self.view).offset(100)
            make.size.equalTo(CGSizeMake(100, 30))
        }
        
        registerButton.snp_makeConstraints { (make) in
            make.top.equalTo(lblText).offset(20)
            make.right.equalTo(self.view).offset(-100)
            make.size.equalTo(CGSizeMake(100, 30))
        }
    }
    
    @objc private func setupNav() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(login))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(login))
    }
    
    @objc private func login() {
        print("xxxx")
    }
    
    lazy var lblText: UILabel = {
        let lblText = UILabel()
        lblText.numberOfLines = 0
        lblText.textAlignment = NSTextAlignment.Center
        return lblText
    }()
    
    lazy var loginButton: UIButton = {
        let loginButton = UIButton()
        loginButton.setTitle("登录", forState: UIControlState.Normal)
        loginButton.addTarget(self, action: #selector(login), forControlEvents: UIControlEvents.TouchUpInside)
        return loginButton
    }()
    
    lazy var registerButton: UIButton = {
        let registerButton = UIButton()
        registerButton.setTitle("注册", forState: UIControlState.Normal)
        registerButton.addTarget(self, action: #selector(login), forControlEvents: UIControlEvents.TouchUpInside)
        return registerButton
    }()
}
